package com.bestcem.xm.ticket.dao.converter;

import com.bestcem.xm.ticket.entity.mongo.NotifySetting;
import com.bestcem.xm.ticket.entity.mysql.NotifySettingDO;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import javax.annotation.Nullable;
import java.util.Objects;

/**
 * DO和DTO转换类
 *
 * @author zhangfeng <feng.zhang@idiaoyan.com>
 * @version v1.0
 * @date 2021/9/17 16:10
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class NotifySettingConverter {

    @Nullable
    public static NotifySetting doToDto(NotifySettingDO notifySettingDO) {
        if (Objects.isNull(notifySettingDO)) {
            return null;
        }
        NotifySetting notifySetting = new NotifySetting();
        notifySetting.setId(notifySettingDO.getNotifySettingId());
        notifySetting.setOrgId(notifySettingDO.getOrgId());
        NotifySetting.Way ways = new NotifySetting.Way();
        ways.setEmail(notifySettingDO.getEmail());
        ways.setSms(notifySettingDO.getSms());
        ways.setFeiShu(notifySettingDO.getFeiShu());
        ways.setWeChatWork(notifySettingDO.getWechatWork());
        ways.setDingtalk(notifySettingDO.getDingtalk());
        notifySetting.setWays(ways);
        notifySetting.setSample(notifySettingDO.getSample());

        CommonConverter.setEntity(notifySetting, notifySettingDO);
        return notifySetting;
    }

    @Nullable
    public static NotifySettingDO dtoToDo(NotifySetting notifySetting) {
        if (Objects.isNull(notifySetting)) {
            return null;
        }
        NotifySettingDO notifySettingDO = new NotifySettingDO();
        notifySettingDO.setNotifySettingId(notifySetting.getId());
        notifySettingDO.setOrgId(notifySetting.getOrgId());
        NotifySetting.Way ways = notifySetting.getWays();
        notifySettingDO.setEmail(ways.getEmail());
        notifySettingDO.setSms(ways.getSms());
        notifySettingDO.setFeiShu(ways.getFeiShu());
        notifySettingDO.setWechatWork(ways.getWeChatWork());
        notifySettingDO.setDingtalk(ways.getDingtalk());
        notifySettingDO.setSample(notifySetting.getSample());

        CommonConverter.setDo(notifySetting, notifySettingDO);
        return notifySettingDO;
    }
}
